<template>
  <div class="app-container"><h4>商户的入金或者余额，提取的方式，只能选择以下其中一种</h4>
    <br><br>当前方式：{{ transferType === 1 ? "立即划转" : "定时划转"}} 
    <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate()"
            v-hasPermi="['bizmanage:set:directly']"
          >修改</el-button>

    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-form-item label-width="150px" label="入金划转方式" prop="transferType">
          <el-radio-group v-model="formData.transferType" size="medium">
            <el-radio v-for="(item, index) in transferTypeOptions" :key="index" :label="item.value"
              :disabled="item.disabled" border>{{item.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item size="large">
          <el-button type="primary" @click="submitForm">提交</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { setTransferSwitch, getTransferSwitch } from "@/api/bizmanage/set";
import Cookies from "js-cookie";

export default {
  components: {},
  props: [],
  data() {
    return {
      open: false,
      transferType: undefined,
      formData: {
        transferType: 1,
      },
      rules: {
        transferType: [{
          required: true,
          message: '入金划转方式不能为空',
          trigger: 'change'
        }],
      },
      transferTypeOptions: [{
        "label": "立即划转",
        "value": 1
      }, {
        "label": "定时划转",
        "value": 2
      }],
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getSwitchStat()
  },
  mounted() {},
  methods: {
    handleUpdate(){
      this.open = true
    },
    getSwitchStat(){
      getTransferSwitch(Cookies.get('username')).then(
        response => {
          this.transferType = response.data === 'directly' ? 1:2;
          this.formData.transferType = this.transferType;
        }
      );
    },
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return;
        // TODO 提交表单
        setTransferSwitch(Cookies.get('username'), this.formData.transferType == 1 ? 'directly':'timing').then(response => {
            if (response.code === 1) {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getSwitchStat();
            }
          });
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields();
    },
  }
}

</script>
<style>
</style>
